164
|
5 Methods for Discrete Processing and Analysis of Biosignals
Listing 5.3.1.1: Matlab example for coherent averaging of signals.
T = 100;
% signal duration
fa = 100;
% sampling frequency
Ta = 1/fa;
% sampling period
tn = 0:1/fa:T-1/fa;
% time vector between 0 and T s
%% s, cosine signal with additive noise
f = 1;
x = -0.5*sin(2*pi*f*tn)+0.*sin(2*2*pi*f*tn);% sum oscillation
a = 0.2;
% noise amplitude
n = randn(size(x));
% random numbers
s = x+(a*n);
% signal with additive noise
subplot(4,2,1);
% graphical representation of signal
plot(tn,x,'LineWidth',2); hold on;
plot(tn,s, '--'); grid on;
legend('without noise', 'with noise')
xlabel('time t /s');
ylabel('amplitude');
axis([0 5 -1.2 1.2]);
subplot(4,2,2);
% graphical representation of spectrum
[orig_Sor,f] = pwelch(x,[],[],[],fa);
[orig_S,f] = pwelch(s,[],[],[],fa);
plot(f,20*log(orig_Sor), f,20*log(orig_S)); grid on;
legend('without noise', 'with noise')
xlabel('frequency f / Hz');
ylabel('amplitude / dB');
axis([0 10 -300 30]);
%% 5-fold coherent averaging of s
N = 5;
average_s=0;
for i=1:N
n=randn(size(x));
s=x+(a*n);
average_s=s/N+average_s;
end
subplot(4,2,3);